package spring.library.LibraryProject.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import spring.library.LibraryProject.interceptor.loginInterceptor;

/**
 * 在这里设置拦截的位置 行为是loginInterceptor
 */
@Configuration
public class webConfig implements WebMvcConfigurer {

    @Autowired
    loginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截library下的所有请求，但是除了library/login.html和library/login.html?xxx,还有各种前端的页面
        // /library/login.html表示不会拦截的是/library/login.html?xxx的
        // /library/login表示不会拦截/library/login?xxx的
        // 而要/library/login/**表示的是不会拦截login/之下的请求，比如/library/login/hadage.html
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/library/**")
//                .excludePathPatterns("/library/login.html")//不拦截对前端资源的访问
                .excludePathPatterns("/library/login")//不拦截对controller的url
//                .excludePathPatterns("/library/unLogin.html")
                .excludePathPatterns("/**/*.html","/**/*.css", "/**/*.js", "/**/*.png");

    }
}
